package com.raindrop.rd.parser.token;

import com.sun.tools.javac.parser.Tokens;

/**
 * token的类型
 *
 * @author BillDowney
 * @date 2021/3/22 11:08
 */
public enum TokenType {
    /**
     * 标识符
     */
    IDENTIFIER("标识符"),
    INT("int", "整数", Tag.NAMED),
    /**
     * 符号
     */
    SEMI(";", "分号"),
    EQ("=", "赋值"),
    DOT(".", "点"),
    LPAREN("(", "左括号"),
    RPAREN(")", "右括号"),
    /**
     * 数字类型
     */
    INT_LITERAL("int", Tag.NUMERIC),
    LONG_LITERAL("long", Tag.NUMERIC),
    FLOAT_LITERAL("float", Tag.NUMERIC),
    DOUBLE_LITERAL("double", Tag.NUMERIC),
    /**
     * 计算符号
     */
    PLUS("+", "加号"),
    SUB("-", "减号"),
    STAR("*", "乘号(*)"),
    SLASH("/", "除号(/)");

    public String mark;
    public final String desc;
    public final Tag tag;

    TokenType(String desc) {
        this(null, desc);
    }

    TokenType(String mark, String desc) {
        this(mark, desc, Tag.DEFAULT);
    }

    TokenType(String desc, Tag tag) {
        this(null, desc, Tag.DEFAULT);
    }

    TokenType(String mark, String desc, Tag tag) {
        this.mark = mark;
        this.desc = desc;
        this.tag = tag;
    }

    @Override
    public String toString() {
        return "TokenType{" +
                "mark='" + mark + '\'' +
                ", desc='" + desc + '\'' +
                ", tag=" + tag +
                '}';
    }

    enum Tag {
        /**
         * 默认标签
         */
        DEFAULT,
        /**
         * 关键字
         */
        NAMED,
        /**
         * 字符串
         */
        STRING,
        /**
         * 数字
         */
        NUMERIC;

        private Tag() {
        }
    }
}
